﻿using System;
using System.Collections.Generic;
using System.Text;

namespace BaseSimpleAPI.ActionResult
{
    public class RedirectResult : IActionResult
    {
        private string _action = null;

        public RedirectResult(string action)
        {
            _action = action ?? throw new Exception("action must not be null");
        }

        public byte[] GetRespondData()
        {
            // 修剪多余的响应头
            ResponseHeaderHelper.GetInstance().TrimResponseHeader("ContentType", "ResponseEncoding", "StatusCode");

            ResponseHeaderHelper.GetInstance().CompletionResponseHeader(new Dictionary<string, string>
            {
                { "StatusCode", "302" },
                { "RedirectAction", _action }
            });

            return ActionResultHelper.GetResponseData(null);

        }
    }
}
